﻿class Config_Json_Rs232
{

    static string 文件名 = "config_rs232.json";
    public string 串口号 = "COM1";
    public string 波特率 = "9600";
    public string 数据位 = "8";
    public string 停止位 = "1";
    public string 奇偶校验 = "None";

    public bool 显示时间 = true;
    public bool 使用16进制 = false;
    public bool 加回车换行符 = true;



    public bool 常用指令加回车 = true;
    public bool 常用指令16进制 = false;

    public string 指令1 = "";
    public string 指令2 = "";
    public string 指令3 = "";
    public string 指令4 = "";
    public string 指令5 = "";
    public string 指令6 = "";
    public string 指令7 = "";
    public string 指令8 = "";

    public string 用途1 = "";
    public string 用途2 = "";
    public string 用途3 = "";
    public string 用途4 = "";
    public string 用途5 = "";
    public string 用途6 = "";
    public string 用途7 = "";
    public string 用途8 = "";

    public string 生产厂商 = "";
    public string 官网 = "";
    public string 名称 = "";
    public string 型号 = "";

    public string 接口 = "待确认";
    public string 连接线= "待确认";

    public static void save(Config_Json_Rs232 config)
    {
        string jsontxt = Newtonsoft.Json.JsonConvert.SerializeObject(config, Newtonsoft.Json.Formatting.Indented);
        using (System.IO.StreamWriter writer = new System.IO.StreamWriter(文件名))
        {
            writer.WriteLine(jsontxt);
            writer.Close();
        }
    }
    public static void save(Config_Json_Rs232 config, string path)
    {
        string jsontxt = Newtonsoft.Json.JsonConvert.SerializeObject(config, Newtonsoft.Json.Formatting.Indented);
        using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path))
        {
            writer.WriteLine(jsontxt);
            writer.Close();
        }
    }


    public static Config_Json_Rs232 ReadAll()
    {
        Config_Json_Rs232 config = new Config_Json_Rs232();
        if (System.IO.File.Exists(文件名) == false)
        {
            string jsontxt = Newtonsoft.Json.JsonConvert.SerializeObject(config);
            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(文件名, true))
            {
                writer.Write(jsontxt);
                writer.Close();
            }
            return config;
        }

        string tt = System.IO.File.ReadAllText(文件名);
        config = Newtonsoft.Json.JsonConvert.DeserializeObject<Config_Json_Rs232>(tt);
        return config;
    }
}